package com.zhuangjie.shop.handler.activity.handler;

import com.zhuangjie.shop.entity.ShopActivityInstance;
import com.zhuangjie.shop.enums.ActivityType;
import com.zhuangjie.shop.handler.activity.ActivityEnv;

import java.math.BigDecimal;
import java.util.Objects;

/**
 * 活动处理器
 */
public abstract class ActivityHandler {

    /**
     * 定义活动类型id
     *
     * @return long
     */
    public abstract ActivityType activityType();

    /**
     * 看活动类型是否满足
     * @param activityTypeId
     * @return
     */
    public boolean equalsActivityType(Long activityTypeId) {
        return Objects.equals(activityType().getCode(),activityTypeId);
    }

    /**
     * 检查活动是否有效
     */
    public abstract void checkActivityValid(ShopActivityInstance shopActivityInstance);

    public abstract BigDecimal calculateDiscountsHandler(ActivityEnv env, ShopActivityInstance shopActivityInstance);
    /**
     * 计算可优惠金额
     */
    public final BigDecimal calculateDiscounts(ActivityEnv env, ShopActivityInstance shopActivityInstance) {
        return calculateDiscountsHandler(env,shopActivityInstance);
    }

}
